import logging

from capsserver.lib.base import *
import urllib2

log = logging.getLogger(__name__)

class CapController(BaseController):

    def handle(self,cap_id):
        # Return a rendered template
        #   return render('/some/template.mako')
        # or, Return a response
        print cap_id
        cap_q = model.Session.query(model.Capability) 
        capobjs = cap_q.filter(model.Capability.uuid==cap_id)
        #if len(capobjs)==0:
        #    abort(404)
        origin = capobjs.one().origin
        
        # now retrieve the page
        r = urllib2.Request(origin,None)
        res = urllib2.urlopen(r)
        return res.read()
